<?php

namespace Chaosyeo\SolarEngine\Event;

class ImpressionAdProperties extends Properties
{
    // 广告类型枚举
    const AD_TYPE_REWARD_VIDEO    = 1;    // 激励视频
    const AD_TYPE_SPLASH          = 2;    // 开屏
    const AD_TYPE_INTERSTITIAL    = 3;    // 插屏
    const AD_TYPE_FULL_VIDEO      = 4;    // 全屏视频
    const AD_TYPE_BANNER          = 5;    // Banner
    const AD_TYPE_FEED            = 6;    // 信息流
    const AD_TYPE_SHORT_VIDEO     = 7;    // 短视频信息流
    const AD_TYPE_LARGE_BANNER    = 8;    // 大横幅
    const AD_TYPE_VIDEO_PATCH     = 9;    // 视频贴片
    const AD_TYPE_MREC            = 10;   // MREC
    const AD_TYPE_OTHER           = 0;    // 其它

    // 变现平台枚举
    const AD_PLATFORM_CSJ         = 'csj';         // 穿山甲国内版
    const AD_PLATFORM_PANGLE      = 'pangle';      // 穿山甲国际版
    const AD_PLATFORM_TENCENT     = 'tencent';     // 腾讯优量汇
    const AD_PLATFORM_BAIDU       = 'baidu';       // 百度百青藤
    const AD_PLATFORM_KUAISHOU    = 'kuaishou';    // 快手
    const AD_PLATFORM_OPPO        = 'oppo';        // OPPO
    const AD_PLATFORM_VIVO        = 'vivo';        // vivo
    const AD_PLATFORM_MI          = 'mi';          // 小米
    const AD_PLATFORM_HUAWEI      = 'huawei';      // 华为
    const AD_PLATFORM_APPLOVIN    = 'applovin';    // Applovin
    const AD_PLATFORM_SIGMOB      = 'sigmob';      // Sigmob
    const AD_PLATFORM_MINTEGRAL   = 'mintegral';   // Mintegral
    const AD_PLATFORM_ONEWAY      = 'oneway';      // OneWay
    const AD_PLATFORM_VUNGLE      = 'vungle';      // Vungle
    const AD_PLATFORM_FACEBOOK    = 'facebook';    // Facebook
    const AD_PLATFORM_ADMOB       = 'admob';       // AdMob
    const AD_PLATFORM_UNITY       = 'unity';       // UnityAds
    const AD_PLATFORM_IS          = 'is';          // IronSource
    const AD_PLATFORM_ADTIMING    = 'adtiming';    // AdTiming
    const AD_PLATFORM_KLEIN       = 'klein';       // 游可赢
    const AD_PLATFORM_FYBER       = 'fyber';       // Fyber
    const AD_PLATFORM_CHARTBOOST  = 'chartboost';  // Chartboost
    const AD_PLATFORM_ADCOLONY    = 'adcolony';    // Adcolony
    const AD_PLATFORM_INMOBI      = 'inmobi';      // Inmobi
    const AD_PLATFORM_WECHAT_MINI = 'wechat_mini'; // 微信小程序/小游戏
    const AD_PLATFORM_DOUYIN_MINI = 'douyin_mini'; // 抖音小程序/小游戏
    const AD_PLATFORM_BIGO        = 'bigo';        // BIGO

    // 聚合平台枚举
    const MEDIATION_MAX          = 'max';
    const MEDIATION_IRONSOURCE   = 'ironsource';
    const MEDIATION_ADMOB        = 'admob';
    const MEDIATION_HYPERBID     = 'hyperbid';
    const MEDIATION_TOPON        = 'topon';
    const MEDIATION_CAS          = 'cas';
    const MEDIATION_TRADPLUS     = 'tradplus';
    const MEDIATION_TOBID        = 'tobid';
    const MEDIATION_GROMORE      = 'gromore';
    const MEDIATION_CUSTOM       = 'custom';

    protected $adPlatform;         // 变现平台
    protected $adAppid;            // 变现平台的应用 ID
    protected $mediationPlatform;  // 聚合平台标识
    protected $adId;               // 变现广告位 ID
    protected $adType;             // 广告类型
    protected $adEcpm;             // 广告展示的ecpm
    protected $currencyType;       // 展示收益的货币种类
    protected $isRendered = true;  // 广告是否渲染成功

    /**
     * @param string $adPlatform 变现平台（必传）
     * @param string $mediationPlatform 聚合平台标识（必传）
     * @param string $adId 变现广告位 ID（必传）
     * @param int $adType 广告类型（必传）
     * @param float $adEcpm 广告展示的ecpm（必传）
     * @param string $currencyType 展示收益的货币种类（必传）
     * @param array $params 可选参数数组，可包含：
     *   - adAppid: string 变现平台的应用 ID
     *   - isRendered: bool 广告是否渲染成功
     */
    public function __construct(
        int $platform,
        string $adPlatform,
        string $mediationPlatform,
        string $adId,
        int $adType,
        float $adEcpm,
        string $currencyType,
        array $params = [],
        array $customProperties = []
    ) {
        if (empty($adPlatform) || !in_array($adPlatform, [
            self::AD_PLATFORM_CSJ,          self::AD_PLATFORM_PANGLE,      self::AD_PLATFORM_TENCENT,
            self::AD_PLATFORM_BAIDU,        self::AD_PLATFORM_KUAISHOU,    self::AD_PLATFORM_OPPO,
            self::AD_PLATFORM_VIVO,         self::AD_PLATFORM_MI,          self::AD_PLATFORM_HUAWEI,
            self::AD_PLATFORM_APPLOVIN,     self::AD_PLATFORM_SIGMOB,      self::AD_PLATFORM_MINTEGRAL,
            self::AD_PLATFORM_ONEWAY,       self::AD_PLATFORM_VUNGLE,      self::AD_PLATFORM_FACEBOOK,
            self::AD_PLATFORM_ADMOB,        self::AD_PLATFORM_UNITY,       self::AD_PLATFORM_IS,
            self::AD_PLATFORM_ADTIMING,     self::AD_PLATFORM_KLEIN,       self::AD_PLATFORM_FYBER,
            self::AD_PLATFORM_CHARTBOOST,   self::AD_PLATFORM_ADCOLONY,    self::AD_PLATFORM_INMOBI,
            self::AD_PLATFORM_WECHAT_MINI,  self::AD_PLATFORM_DOUYIN_MINI, self::AD_PLATFORM_BIGO
        ])) {
            throw new \InvalidArgumentException('Invalid ad platform');
        }

        if (empty($mediationPlatform) || !in_array($mediationPlatform, [
            self::MEDIATION_MAX,        self::MEDIATION_IRONSOURCE, self::MEDIATION_ADMOB,
            self::MEDIATION_HYPERBID,   self::MEDIATION_TOPON,      self::MEDIATION_CAS,
            self::MEDIATION_TRADPLUS,   self::MEDIATION_TOBID,      self::MEDIATION_GROMORE,
            self::MEDIATION_CUSTOM
        ])) {
            throw new \InvalidArgumentException('Invalid mediation platform');
        }

        if (empty($adId)) {
            throw new \InvalidArgumentException('Ad ID is required');
        }

        if (!in_array($adType, [
            self::AD_TYPE_REWARD_VIDEO, self::AD_TYPE_SPLASH,       self::AD_TYPE_INTERSTITIAL,
            self::AD_TYPE_FULL_VIDEO,   self::AD_TYPE_BANNER,       self::AD_TYPE_FEED,
            self::AD_TYPE_SHORT_VIDEO,  self::AD_TYPE_LARGE_BANNER, self::AD_TYPE_VIDEO_PATCH,
            self::AD_TYPE_MREC,         self::AD_TYPE_OTHER
        ])) {
            throw new \InvalidArgumentException('Invalid ad type');
        }

        if ($adEcpm <= 0) {
            throw new \InvalidArgumentException('Ad ECPM must be greater than 0');
        }

        if (empty($currencyType)) {
            throw new \InvalidArgumentException('Currency type is required');
        }

        $this->adPlatform        = $adPlatform;
        $this->mediationPlatform = $mediationPlatform;
        $this->adId             = $adId;
        $this->adType           = $adType;
        $this->adEcpm           = $adEcpm;
        $this->currencyType     = $currencyType;

        // 设置可选参数
        if (isset($params['adAppid'])) {
            $this->adAppid = $params['adAppid'];
        }
        if (isset($params['isRendered'])) {
            $this->isRendered = $params['isRendered'];
        }

        parent::__construct($platform, $params, $customProperties);
    }
}